package NG::Gen::Task::BuyLeader;
use strict;
use warnings;
use utf8;

use NG::Sys::App;

use NG::Sys::Datetime;
our @ISA = qw(NG::Gen::Task::Task);

sub before_assign {
	my $self = shift;
	if($self->{user}->l_point < 1){
		return "Недостаточно средств"
	}
	my %avail = map {$_=>1} split /,/, $self->param->{types};
	unless($avail{$self->param->{type}}){
		return "Это не доступно";
	}
	return 0;
}
sub after_assign {
	my $self = shift;
	$self->{user}->l_point($self->{user}->l_point - 1);
	return 0;
}
sub before_done {
	my $self = shift;
	my $leader = app()->reference("leaders")->get_by_key($self->param->{type});
	$self->{user}->add_leader($leader);
	return 0;
}
sub after_done {
	my $self = shift;
	$self->refresh_user(0);
	return 0;
}
sub after_cancel {
	my $self = shift;
	$self->{user}->l_point($self->{user}->l_point + 1);
	return 0;
}

1;
